<?php

/**
 * Transaction filter form base class.
 *
 * @package    Amawal Invest
 * @subpackage filter
 * @author     Ameen Shoman<amin.shoman@gmail.com>
 */
abstract class BaseTransactionFormFilter extends BaseFormFilterPropel
{
  public function setup()
  {
    $this->setWidgets(array(
      'employee_id'       => new sfWidgetFormPropelChoice(array('model' => 'Employee', 'add_empty' => true)),
      'transaction_type'  => new sfWidgetFormFilterInput(),
      'leave_type_id'     => new sfWidgetFormPropelChoice(array('model' => 'CodeLeaveType', 'add_empty' => true)),
      'vacation_type'     => new sfWidgetFormFilterInput(),
      'date_from'         => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'date_to'           => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'period'            => new sfWidgetFormFilterInput(),
      'created_at'        => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'updated_at'        => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'notification_flag' => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'approve_flag'      => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'modification_flag' => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'branch_id'         => new sfWidgetFormPropelChoice(array('model' => 'Branch', 'add_empty' => true)),
    ));

    $this->setValidators(array(
      'employee_id'       => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Employee', 'column' => 'id')),
      'transaction_type'  => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'leave_type_id'     => new sfValidatorPropelChoice(array('required' => false, 'model' => 'CodeLeaveType', 'column' => 'id')),
      'vacation_type'     => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'date_from'         => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDate(array('required' => false)))),
      'date_to'           => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDate(array('required' => false)))),
      'period'            => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'created_at'        => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDate(array('required' => false)))),
      'updated_at'        => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDate(array('required' => false)))),
      'notification_flag' => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'approve_flag'      => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'modification_flag' => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'branch_id'         => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Branch', 'column' => 'id')),
    ));

    $this->widgetSchema->setNameFormat('transaction_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    parent::setup();
  }

  public function getModelName()
  {
    return 'Transaction';
  }

  public function getFields()
  {
    return array(
      'id'                => 'Number',
      'employee_id'       => 'ForeignKey',
      'transaction_type'  => 'Number',
      'leave_type_id'     => 'ForeignKey',
      'vacation_type'     => 'Number',
      'date_from'         => 'Date',
      'date_to'           => 'Date',
      'period'            => 'Number',
      'created_at'        => 'Date',
      'updated_at'        => 'Date',
      'notification_flag' => 'Boolean',
      'approve_flag'      => 'Boolean',
      'modification_flag' => 'Boolean',
      'branch_id'         => 'ForeignKey',
    );
  }
}
